//created by: Justina Lee

Ext.define("MajorProjectSenchaTouch.view.BookMarkedModule.BookMarkedDataview", {
    extend: 'Ext.dataview.DataView',
    xtype: 'BookMarkedDV',
    requires:[
    'MajorProjectSenchaTouch.store.BookMarkedMemory',
    'MajorProjectSenchaTouch.view.BookMarkedModule.ResultListItem',
    'Ext.plugin.ListPaging'
    ],
    config: {
        fullscreen:true,
        useComponents:true,
        store:'BookMarkedMemory',
        defaultType:'resultListItem',
        plugins: [
        {
            xclass: 'Ext.plugin.ListPaging',
            id: 'bmListPaging',
            loadMoreText: 'Loading...',
            noMoreRecordsText: 'No More Records',
            
            //override plugin config and methods
            loadMoreCmp: {
                xtype: 'component',
                baseCls: Ext.baseCSSPrefix + 'list-paging'
            },
            loadTpl: [
                '<div class="{cssPrefix}list-paging-msg">{message}</div>'
            ].join(''),
            applyLoadMoreCmp: function(config) {
                config = Ext.merge(config, {
                    html: this.getLoadTpl().apply({
                        cssPrefix: Ext.baseCSSPrefix,
                        message: this.getLoadMoreText()
                    })
                });

                return Ext.factory(config, Ext.Component, this.getLoadMoreCmp());
            }
            
        }
        ],
        listeners:{
            painted: function(){
                var scroller = this.getScrollable().getScroller();
            
                scroller.on('scrollend', function(scroller, x, y) {
                    if (y >= scroller.maxPosition.y) {
                        //you have scrolled to the end of the list
                        this.fireEvent('loadMoreRecords', this, scroller, y);
                    }
                }, this);
            }
        }
    }
});